package com.ruoyi.project.comp.share.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.comp.share.domain.CompShare;
import com.ruoyi.project.comp.share.service.ICompShareService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 作品转发记录Controller
 * 
 * @author ruoyi
 * @date 2025-11-02
 */
@Controller
@RequestMapping("/comp/share")
public class CompShareController extends BaseController
{
    private String prefix = "comp/share";

    @Autowired
    private ICompShareService compShareService;

    @RequiresPermissions("comp:share:view")
    @GetMapping()
    public String share()
    {
        return prefix + "/share";
    }

    /**
     * 查询作品转发记录列表
     */
    @RequiresPermissions("comp:share:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CompShare compShare)
    {
        startPage();
        List<CompShare> list = compShareService.selectCompShareList(compShare);
        return getDataTable(list);
    }

    /**
     * 导出作品转发记录列表
     */
    @RequiresPermissions("comp:share:export")
    @Log(title = "作品转发记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CompShare compShare)
    {
        List<CompShare> list = compShareService.selectCompShareList(compShare);
        ExcelUtil<CompShare> util = new ExcelUtil<CompShare>(CompShare.class);
        return util.exportExcel(list, "作品转发记录数据");
    }

    /**
     * 新增作品转发记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存作品转发记录
     */
    @RequiresPermissions("comp:share:add")
    @Log(title = "作品转发记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CompShare compShare)
    {
        return toAjax(compShareService.insertCompShare(compShare));
    }

    /**
     * 修改作品转发记录
     */
    @RequiresPermissions("comp:share:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CompShare compShare = compShareService.selectCompShareById(id);
        mmap.put("compShare", compShare);
        return prefix + "/edit";
    }

    /**
     * 修改保存作品转发记录
     */
    @RequiresPermissions("comp:share:edit")
    @Log(title = "作品转发记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CompShare compShare)
    {
        return toAjax(compShareService.updateCompShare(compShare));
    }

    /**
     * 删除作品转发记录
     */
    @RequiresPermissions("comp:share:remove")
    @Log(title = "作品转发记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(compShareService.deleteCompShareByIds(ids));
    }
}
